package com.yituo.mjworld.mvc.action.admin;

import com.yituo.mjworld.core.annotation.Check;
import com.yituo.mjworld.core.web.core.MyHttpRequest;
import com.yituo.mjworld.core.web.core.MyHttpResponse;
import com.yituo.mjworld.mvc.entity.web.UserRole;
import com.yituo.mjworld.mvc.entity.web.WebUser;
import com.yituo.mjworld.mvc.form.QueryForm;
import com.yituo.mjworld.mvc.service.impl.DataServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 数据统计模块
 */
@Component
public class DataAction {
  @Autowired
  DataServiceImpl dataService;

  /**
   * 获取我推广的代理的销售业绩
   *
   * @param req
   * @param res
   * @throws IOException
   */
  public void getSaleData(MyHttpRequest req, MyHttpResponse res) throws IOException {
    
  }

  /**
   * 查询我的子用户
   */
  @Check(form = QueryForm.class)
  public void getMyUser(MyHttpRequest req, MyHttpResponse res) throws IOException {
    // 如果是普通用户来查询,则只显示其推广人数
    WebUser user = req.getCurrentUser();
    QueryForm form = (QueryForm) req.getForm();
    if (UserRole.isWebUser(user)) {
      res.success(dataService.getMyUserNum(user));
    } else {
      res.success(dataService.getMyUser(form, user));
    }

  }
}
